from __future__ import absolute_import, unicode_literals
import os
from celery import Celery

# set the default Django settings module for the 'celery' program.
#加载项目环境
os.environ.setdefault("DJANGO_SETTINGS_MODULE","meiduo_mall.settings.dev")

#创建celeryd、对象
app = Celery('meiduo_mall')

# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
#   should have a `CELERY_` prefix.
#加载配置
app.config_from_object('celery_tasks.config.', namespace='CELERY')

# Load task modules from all registered Django app configs.
#自动注册任务
app.autodiscover_tasks(['celery_tasks.test','celery_tasks.sms'])

#手动添加任务
# @app.task(bind=True)
# def sum(self,num1,num2):
#     return num1 + num2




# 启动   $ celery -A proj worker -l info
# #发送  任务名称 delay
# $ python ./manage.py shell
# >>> from demoapp.tasks import add, mul, xsum
# >>> res = add.delay(2,3)
# >>> res.get()
# 5
